//
//  ZBProductItem.m
//  XZBProduct
//
//  Created by xzb on 2018/12/25.
//  Copyright © 2018 xzb. All rights reserved.
//

#import "ZBProductItem.h"

@implementation ZBProductItem


- (nonnull id<NSObject>)diffIdentifier {
    return self.title;
}

- (BOOL)isEqualToDiffableObject:(nullable ZBProductItem<IGListDiffable> *)object {
    return [self isEqual:object];
}

- (BOOL)isEqual:(ZBProductItem *)object
{
    if (self == object) {
        return YES;
    } else if (self == nil || object == nil || ![object isKindOfClass:[self class]]) {
        return NO;
    }
    return
    _styleType == object->_styleType &&
    _price == object->_price &&
    _iid == object->_iid &&
    (_img == object->_img ? YES : [_img isEqual:object->_img]) &&
    (_title == object->_title ? YES : [_title isEqual:object->_title]) &&
    (_desc == object->_desc ? YES : [_desc isEqual:object->_desc]) &&
    (_rect_img == object->_rect_img ? YES : [_rect_img isEqual:object->_rect_img]);
}


- (NSUInteger)hash
{
    NSUInteger subhashes[] = {_styleType, [_img hash], [_title hash], ABS(_price), ABS(_iid), [_desc hash], [_rect_img hash]};
    NSUInteger result = subhashes[0];
    for (int ii = 1; ii < 7; ++ii) {
        unsigned long long base = (((unsigned long long)result) << 32 | subhashes[ii]);
        base = (~base) + (base << 18);
        base ^= (base >> 31);
        base *=  21;
        base ^= (base >> 11);
        base += (base << 6);
        base ^= (base >> 22);
        result = base;
    }
    return result;
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"%@ - \n\t styleType: %tu; \n\t image: %@; \n\t title: %@; \n\t price: %zd; \n\t iid: %zd; \n\t desc: %@; \n\t rect_img: %@; \n", [super description], _styleType, _img, _title, _price, _iid, _desc, _rect_img];
}

@end
